﻿namespace SchemeFileSystem.Providers
{
    using System.IO;

    using SchemeFileSystem.Internals;

    public class File : IFilesystem
    {
        protected string Pathing;

        protected string scheme;

        public File()
        {
            scheme = "file://";
        }

        #region Overrides of IFilesystem

        public override string[] Schemes
        {
            get
            {
                return new[] { scheme };
            }
        }

        public override void CreateFile(string path, string content)
        {
            System.IO.File.WriteAllText(Pathing + path.Replace(scheme, ""), content);
        }

        public override void CreateFolder(string path)
        {
            Directory.CreateDirectory(Pathing + path.Replace(scheme, ""));
        }

        public override string[] GetFiles(string path)
        {
            var f = Pathing + path.Replace(scheme, "");
            return Directory.GetFiles(f);
        }

        public override string[] GetFolders(string path)
        {
            return Directory.GetDirectories(Pathing + path.Replace(scheme, ""));
        }

        public override string ReadFile(string path)
        {
            return System.IO.File.ReadAllText(Pathing + path.Replace(scheme, ""));
        }

        public override void Delete(string path)
        {
            System.IO.File.Delete(Pathing + path);
        }

        public override void Mount(char pathletter, string path)
        {
            VirtualDrive.Create(pathletter, path);
        }

        public override void Unmount(char pathletter, string path)
        {
            VirtualDrive.Delete(pathletter, path);
        }

        #endregion
    }
}
